/*
 * Thread.cpp
 *
 */

#include "Thread.h"

ThreadException::ThreadException(const std::string& msg) throw() : msg(msg) {}

Thread::~Thread() {
	die();
}

void Thread::start() {
	dead = false;
	if (pthread_create(&ptr, NULL, &func, (void*)this) != 0)
		throw ThreadException("Error de lanzamiento de hilo");
}

void Thread::join() {
	pthread_join(ptr, NULL);
}

bool Thread::isDead() const {
	return dead;
}

void Thread::die() {
	dead = true;
}

void* Thread::func(void* datos) {
	Thread* hilo = (Thread*)datos;
	hilo->run();
	return NULL;
}
